package com.mp.approvalreq.servlet;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.service.SelectApprovalServicePrx;
import com.plusmoney.util.ParameterUtils;
import com.plusmoney.util.Utils;
import com.qq.tars.client.util.ServantUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/transferData")
public class TransferData extends AbstractServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String companyIds = ParameterUtils.getIntegerArrayParameter(req, "companyIds");
			List<Integer> companyIdList = Utils.string2list(companyIds);

			SelectApprovalServicePrx selectApprovalServicePrx = ServantUtils.getObject(SelectApprovalServicePrx.class);
			selectApprovalServicePrx.transferData(companyIdList);

			returnResult(resp);
		} catch (Throwable throwable) {
			onThrowable(req, resp, throwable);
		}
	}

	protected void returnResult(HttpServletResponse resp) throws IOException {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("result", "0");
		jsonObject.put("res_info", "提交成功");

		printJson(resp, jsonObject.toJSONString());
	}

}
